import socket
from fastapi import APIRouter, Depends
from appCustomers.utils.sec_utils import token_validate, oauth2_scheme
from appCustomers.utils import customers_utl
from appCustomers.schemas import customers

host_name = socket.gethostname()
ip_address = socket.gethostbyname(host_name)

router = APIRouter()

@router.get("/health")
async def health_check():
    return {"Hello": f"World appCustomers from {host_name}({ip_address})"}

@router.post("/process_data")
async def process_data(data: dict):
    processed_data = {key: value.upper() for key, value in data.items()}
    return processed_data

@router.post("/token")
#todo remove the route as it was created for testing purpose
async def login_for_access_token(customer: customers.sCustomerLogin):
    return await customers_utl.sign_in_customer(logcustomer=customer)

@router.get("/protected")
async def protected_route(acc_token: str = Depends(oauth2_scheme)):
    token_validate(acc_token)

@router.post("/customer/sign-up")
async def create_user(customer: customers.sCustomerCreate):
    return await customers_utl.create_customer(newcustomer=customer)

@router.get("/customer/login")
async def login_user(customer: customers.sCustomerLogin):
    return await customers_utl.sign_in_customer(logcustomer=customer)

@router.get("/customer/check")
async def check_customer(customer: customers.sCustomerCheck, acc_token: str = Depends(oauth2_scheme)):
    print("appCustomer: check started")
    token_validate(acc_token)
    print("appCustomer: token checked")
    return await customers_utl.do_cust_check(chkcustomer=customer)

@router.post("/customer/update")
async def update_user(customer: customers.sCustomerUpdate, acc_token: str = Depends(oauth2_scheme)):
    token_validate(acc_token)
    return await customers_utl.update_customer(updcustomer=customer)

@router.delete("/customer/update")
async def delete_user(customer: customers.sCustomerDelete, acc_token: str = Depends(oauth2_scheme)):
    token_validate(acc_token)
    return await customers_utl.delete_customer(delcustomer=customer)